using Quartz;
using Publicuse.Interface;
using Publicuse.Util.QuartZ;

namespace Geekeradmin.ExtendsService
{
    /// <summary>
    /// 初始化后台作业任务
    /// </summary>
    public class QuartzService : BackgroundService
    {

        private readonly IMySqlSugarService baseService;

        private readonly IWebHostEnvironment env;

        private readonly ISchedulerFactory schedulerFactory;

        private readonly IServiceProvider services;

        /// <summary>
        /// 初始化依赖注入
        /// </summary>
        /// <param name="services"></param>
        /// <param name="schedulerFactory"></param>
        /// <param name="baseService"></param>
        /// <param name="env"></param>
        public QuartzService(IMySqlSugarService baseService, IServiceProvider services, ISchedulerFactory schedulerFactory, IWebHostEnvironment env)
        {
            this.services = services;
            this.schedulerFactory = schedulerFactory;
            this.baseService = baseService;
            this.env = env;
        }

        /// <summary>
        /// 初始化后台作业任务
        /// </summary>
        /// <param name="stoppingToken"></param>
        /// <returns></returns>
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await Task.Delay(10000, stoppingToken);
            QuartzTaskExtension.InitQuartzTask(this.services, this.schedulerFactory, this.baseService, this.env);
        }
    }
}
